package com.lesso.zgs.sunflower.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.zgs.sunflower.core.ApiResponse;
import com.lesso.zgs.sunflower.pojo.dto.EmployeeAttendanceRuleDTO;
import com.lesso.zgs.sunflower.pojo.dto.EmployeeAttendanceRuleQueryDTO;
import com.lesso.zgs.sunflower.pojo.vo.EmployeeAttendanceRuleVO;
import com.lesso.zgs.sunflower.service.IEmployeeAttendanceRuleService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 员工考勤规则关系 前端控制器
 * </p>
 *
 * @author zgs
 * @since 2025-07-03
 */

@RestController
@RequestMapping("/employee/attendance-rule")
public class EmployeeAttendanceRuleController {
    @DubboReference
    private IEmployeeAttendanceRuleService employeeAttendanceRuleService;

    /**
     * 为员工分配考勤规则
     */
    @PostMapping("/assign")
    public ResponseEntity<Integer> assignRule(@RequestBody EmployeeAttendanceRuleDTO dto) {
        return ResponseEntity.ok(employeeAttendanceRuleService.assignRule(dto));
    }

    /**
     * 取消员工考勤规则
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Integer> cancelRule(@PathVariable Long id) {
        return ResponseEntity.ok(employeeAttendanceRuleService.cancelRule(id));
    }

    /**
     * 分页查询员工考勤规则关系
     */
    @GetMapping("/page")
    public ApiResponse<Page<EmployeeAttendanceRuleVO>> page(EmployeeAttendanceRuleQueryDTO dto) {
        return ApiResponse.ok("success", employeeAttendanceRuleService.page(dto));
    }

    /**
     * 根据员工ID查询考勤规则
     */
    @GetMapping("/employee/{employeeId}")
    public ApiResponse<List<EmployeeAttendanceRuleVO>> getByEmployeeId(@PathVariable Long employeeId) {
        return ApiResponse.ok("success", employeeAttendanceRuleService.getByEmployeeId(employeeId));
    }
} 